package com.hu.mapper;

import com.hu.entity.dto.UserRegisterDTO;
import com.hu.entity.pojo.UserEntity;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface UserMapper {

    /**
     * 新增用户
     */
    @Insert("insert into user(username, phone, password) values (#{username},#{phone},#{password})")
    void insertUser(UserRegisterDTO userRegisterDTO);

    /**
     * 根据手机号和密码查询用户
     * @param userRegisterDTO
     * @return
     */
    @Select("select * from user where phone = #{phone} and password = #{password}")
    UserEntity selectByPhoneAndPassword(UserRegisterDTO userRegisterDTO);

    /**
     * 根据手机号查询用户
     * @param userRegisterDTO
     * @return
     */
    @Select("select * from user where phone = #{phone}")
    UserEntity selectByPhone(UserRegisterDTO userRegisterDTO);

    /**
     * 查找用户用id或phone或password
     */
    UserEntity selectUser(UserEntity userEntity);

    /**
     * 修改用户信息
     * @param userEntity
     */
    void updateUserInfoById(UserEntity userEntity);

    /**
     * 将用户的题目数减一
     */
    @Update("update user set question_num = question_num - 1 where id = #{userId}")
    void deleteQuestionNum(Long userId);
}
